﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UC_Group_List.ascx.cs" Inherits="QuanLyKhachSan.UC_Group_List" %>
<%@ Register Assembly="Telerik.Web.UI, Version=2011.2.712.35, Culture=neutral, PublicKeyToken=121FAE78165BA3D4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<script type="text/javascript" language="javascript">
    function frmThemGroup_Open() {
        try {
            var URL = '<%=ResolveUrl("~/Pages/PopUp.aspx")%>';
            URL += "?UCName=UC_Group_Edit&UCPath=QuanLyUsers"
            var oRadWindowManager = $find("<%= RadWindowManager1.ClientID %>");
            var frmThemGroup = oRadWindowManager.open(URL, "frmThemGroup");
            frmThemGroup.SetSize(400, 230);
            frmThemGroup.add_close(Group_Load);
        } catch (e) {
            alert(e);
        }
    }
    function frmThemGroup_Edit(GroupID) {
        try {
            var URL = '<%=ResolveUrl("~/Pages/PopUp.aspx")%>';
            URL = URL + "?UCName=UC_Group_Edit&UCPath=QuanLyUsers&GroupID=" + GroupID;
            var oRadWindowManager = $find("<%= RadWindowManager1.ClientID %>");
            var frmThemGroup = oRadWindowManager.open(URL, "frmThemGroup");
            frmThemGroup.SetSize(400, 230);
            frmThemGroup.add_close(Group_Load);
        } catch (e) {
            alert(e);
        }
    }
    function Group_Delete(GroupID, GroupName) {
        try {
            var retOK = confirm("Bạn muốn xóa thông tin loại phòng : " + GroupName);
            if (retOK) {
                var URLService = '<%=ResolveUrl("~/Service/QuanLyUsers/Group.asmx")%>';
                var Method = "Group_Delete";
                $.ajax({
                    type: "POST",
                    url: URLService + "/" + Method,
                    data: "{GroupID:" + '"' + GroupID + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    error: OnError
                });
            }
        } catch (e) {
            alert(e);
        }
    }
    function OnSuccess(data, status) {
        __doPostBack('<%=pnlGroup.ClientID%>', '');
    }

    function OnError(request, status, error) {
        alert("Có sự cố trong quá trình xử lý.Vui lòng kiểm tra lại!");
    }
    function cmdThemGroup_OnClientClicking(sender, args) {
        try {
            args.set_cancel(true);
            frmThemGroup_Open();
        } catch (e) {

        }
    }
    function Group_Load(sender) {
        try {
            //remove the handler
            sender.remove_close(Group_Load);
            var hfTrigger = document.getElementById('<%=hfTrigger.ClientID%>');
            if (hfTrigger.value == "isUpdated") {
                __doPostBack('<%=pnlGroup.ClientID%>', '');
            }                      
            hfTrigger.value = "";
        } catch (e) {
            alert(e);
        }    
    }
    function Close(retTrigger) {
        try {
            var hfTrigger = document.getElementById('<%=hfTrigger.ClientID%>');
            hfTrigger.value = retTrigger;
            var oManager = GetRadWindowManager();
            oManager.closeAll();
        } catch (e) {
            alert(e);
        }
    }     
</script>
  <telerik:RadWindowManager ID="RadWindowManager1" runat="server" 
            EnableShadow="true" Skin="Windows7" Modal="true" VisibleStatusbar="false" >
            <Windows>
                 <telerik:RadWindow  
                    id="frmThemGroup" 
                    runat="server"
                    showcontentduringload="false"
                    width="530px"
                    height="400px"
                    title="Cập nhật nhóm"
                    behaviors="Close,Move,Resize,Maximize"  Animation="Resize" ReloadOnShow="true">
                </telerik:RadWindow>
            </Windows>
  </telerik:RadWindowManager>
<!-- List -->
<table width="100%">
    <tr>
        <td>
            <asp:UpdatePanel ID="pnlGroup" runat="server">
                <ContentTemplate>
                    <telerik:RadGrid ID="lstGroup" runat="server" Skin="Windows7">
                        <MasterTableView DataKeyNames="GroupID" AutoGenerateColumns="false" GridLines="None">
                            <CommandItemSettings ExportToPdfText="Export to Pdf" />   
                            <Columns>                   
                                <telerik:GridTemplateColumn HeaderText="Danh Sách Nhóm">
                                    <ItemTemplate>
                                        <%#Eval("GroupName")%>
                                    </ItemTemplate>
                                    <ItemStyle HorizontalAlign="Left" />
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Chỉnh sửa">
                                    <ItemTemplate>
                                        <span onclick="frmThemGroup_Edit(this.title)" title='<%#Eval("GroupID") %>' style=" cursor:pointer">Sửa </span>|<span onclick="Group_Delete(this.id,this.title)" title='<%#Eval("GroupName") %>' id='<%#Eval("GroupID") %>' style=" cursor:pointer"> Xóa</span>                                                                                
                                    </ItemTemplate>
                                    <HeaderStyle HorizontalAlign="Center" Width="70" />
                                    <ItemStyle HorizontalAlign="Center" />
                                </telerik:GridTemplateColumn>                                
                            </Columns>                    
                        </MasterTableView>          
                    </telerik:RadGrid>              
                </ContentTemplate>
            </asp:UpdatePanel>        
        </td>
    </tr>
    <tr>
        <td>            
            <telerik:RadButton ID="cmdThemGroup" runat="server" Text="Thêm nhóm" OnClientClicking="cmdThemGroup_OnClientClicking">
            </telerik:RadButton>
        </td>
    </tr>
    <tr>
        <td>
            <asp:UpdateProgress ID="pnlProgress" runat="server" AssociatedUpdatePanelID="pnlGroup">
                <ProgressTemplate>
                    <asp:Label ID="lblProgress" runat="server" Text="Đang cập nhật..." Font-Bold="true" ForeColor="Red" Font-Italic="true"></asp:Label>
                </ProgressTemplate>
            </asp:UpdateProgress>
        </td>
    </tr>
</table>
<asp:HiddenField ID="hfTrigger" runat="server" />
